package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysContractSpd;
import com.ruoyi.system.service.ISysContractSpdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业绩分配Controller
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/system/spd")
public class SysContractSpdController extends BaseController
{
    @Autowired
    private ISysContractSpdService sysContractSpdService;

    /**
     * 查询业绩分配列表
     */
    @PreAuthorize("@ss.hasPermi('system:spd:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysContractSpd sysContractSpd)
    {
        startPage();
        List<SysContractSpd> list = sysContractSpdService.selectSysContractSpdList(sysContractSpd);
        return getDataTable(list);
    }

    /**
     * 导出业绩分配列表
     */
    @PreAuthorize("@ss.hasPermi('system:spd:export')")
    @Log(title = "业绩分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysContractSpd sysContractSpd)
    {
        List<SysContractSpd> list = sysContractSpdService.selectSysContractSpdList(sysContractSpd);
        ExcelUtil<SysContractSpd> util = new ExcelUtil<SysContractSpd>(SysContractSpd.class);
        util.exportExcel(response, list, "业绩分配数据");
    }

    /**
     * 获取业绩分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:spd:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysContractSpdService.selectSysContractSpdById(id));
    }

    /**
     * 新增业绩分配
     */
    //@PreAuthorize("@ss.hasPermi('system:spd:add')")
    @Log(title = "业绩分配", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody List<SysContractSpd> sysContractSpdList)
    {
        return toAjax(sysContractSpdService.insertSysContractSpd(sysContractSpdList));
    }

    /**
     * 修改业绩分配
     */
    @PreAuthorize("@ss.hasPermi('system:spd:edit')")
    @Log(title = "业绩分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysContractSpd sysContractSpd)
    {
        return toAjax(sysContractSpdService.updateSysContractSpd(sysContractSpd));
    }

    /**
     * 删除业绩分配
     */
    //@PreAuthorize("@ss.hasPermi('system:spd:remove')")
    @Log(title = "业绩分配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysContractSpdService.deleteSysContractSpdByIds(ids));
    }
}